package com.baizhi.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    //给交换机的bean对象起个id名字叫xExchange
    @Bean("empExchange")
    public DirectExchange directExchange(){
        //在rabbitmq中创建一个叫X的交换机
        return new DirectExchange("emp");
    }

    @Bean("empadd")  //bean id=queueA
    public Queue queueadd(){
        return QueueBuilder.durable("empadd").build();
    }

    @Bean("empdelete")
    public Queue queuedelete(){
        return QueueBuilder.durable("empdelete").build();
    }
    @Bean
    //指定交换机和队列之间的绑定关系
    public Binding queueaddBindingEmp(@Qualifier("empadd") Queue empadd,
                                  @Qualifier("empExchange") DirectExchange emp){
        //指定queueA和xExchange进行绑定
        return BindingBuilder.bind(empadd).to(emp).with("add");
    }
    @Bean
    //指定交换机和队列之间的绑定关系
    public Binding queuebBindingX(@Qualifier("empdelete") Queue empdelete,
                                  @Qualifier("empExchange")DirectExchange emp){
        //指定queueA和xExchange进行绑定
        return BindingBuilder.bind(empdelete).to(emp).with("delete");
    }
}
